package com.wenwu.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wenwu.common.bean.RelicsDictionary;
import com.wenwu.common.bean.RelicsDictionaryExample;
import com.wenwu.common.exception.RelicsException;
import com.wenwu.common.page.PaginationVO;
import com.wenwu.dao.RelicsDictionaryMapper;
import com.wenwu.service.DictionaryService;

/**
 * @project RelicsProject-service
 * @class DictionaryServiceImpl.java
 * @author zhujiagui E-mail:<zhujiagui@zkingsoft.com>
 * @date 2015年5月1日 下午4:44:14
 * @description
 */
@Service
public class DictionaryServiceImpl implements DictionaryService {
	@Autowired
	private RelicsDictionaryMapper dictionaryMapper;

	public int selectTotalRecord(RelicsDictionary dictionary)
			throws RelicsException {
		try {
			return dictionaryMapper.selectTotalRecord(dictionary);
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}

	public List<RelicsDictionary> selectList(RelicsDictionary dictionary,
			PaginationVO pageVo) throws RelicsException {
		try {
			return dictionaryMapper.selectList(dictionary, pageVo);
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}

	public String addObj(RelicsDictionary dictionary) throws RelicsException {
		try {
			int result = 0;
			if (dictionary.getDictionaryId() == null) {
				result = dictionaryMapper.insertSelective(dictionary);
				if (result > 0) {
					return "添加字典成功";
				} else {
					return "添加字典失败";
				}
			} else {
				result = dictionaryMapper
						.updateByPrimaryKeySelective(dictionary);
				if (result > 0) {
					return "修改字典成功";
				} else {
					return "修改字典失败";
				}
			}
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}

	public RelicsDictionary selectObjByKey(Integer dictionaryId)
			throws RelicsException {
		try {
			return dictionaryMapper.selectByPrimaryKey(dictionaryId);
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}

	public int deleteInfoByKey(List<?> keys) throws RelicsException {
		try {
			return dictionaryMapper.deleteInfoByKey(keys);
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}

	public List<RelicsDictionary> selectListByExample(
			RelicsDictionaryExample example) throws RelicsException {
		try {
			return dictionaryMapper.selectByExample(example);
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}
}
